//
//  AppDelegate.m
//  Travel
//
//  Created by dllo on 15/11/28.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "AppDelegate.h"
#import "CXRecommendViewController.h"
#import "CXDestinationViewController.h"
#import "ZZXStrategyViewController.h"
#import "CXMineViewController.h"
#import "CXDestinationViewController.h"
#import "APService.h"

@interface AppDelegate ()<UIScrollViewDelegate>
@property (nonatomic, retain) UIScrollView *scrollView;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    //显示window
    [self.window makeKeyAndVisible];
    [self createTabBar];
    
    
    
   //引导页
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"] == NO) {
        //判断程序是否时第一次登陆
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        self.scrollView = [[UIScrollView alloc] initWithFrame:self.window.frame];
        //self.scrollView.backgroundColor = [UIColor redColor];
        self.scrollView.delegate = self;
        [self.scrollView setContentSize:CGSizeMake(self.window.frame.size.width * 4, self.window.frame.size.height)];
        self.scrollView.pagingEnabled = YES;
        self.scrollView.showsHorizontalScrollIndicator = NO;
        self.scrollView.bounces = NO;
        [self.window addSubview:self.scrollView];
        
        UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, self.window.frame.size.height)];
        image1.image = [UIImage imageNamed:@"bbb.jpg"];
        [self.scrollView addSubview:image1];
        
        UIImageView *image2 = [[UIImageView alloc] initWithFrame:CGRectMake(self.window.frame.size.width , 0, self.window.frame.size.width, self.window.frame.size.height)];
        image2.image = [UIImage imageNamed:@"ccc.jpg"];
        [self.scrollView addSubview:image2];
        
        UIImageView *image3 = [[UIImageView alloc] initWithFrame:CGRectMake(self.window.frame.size.width * 2, 0, self.window.frame.size.width, self.window.frame.size.height)];
        image3.image = [UIImage imageNamed:@"aaa.jpg"];
        [self.scrollView addSubview:image3];
        
        UIImageView *image4 = [[UIImageView alloc] initWithFrame:CGRectMake(self.window.frame.size.width * 3, 0, self.window.frame.size.width, self.window.frame.size.height)];
        image4.image = [UIImage imageNamed:@"dd.jpeg"];
        [self.scrollView addSubview:image4];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
<<<<<<< HEAD
        button.frame = CGRectMake( 120 *WIDTH , 600 * HEIGHT, 120 * WIDTH , 50 * HEIGHT );
=======
        button.frame = CGRectMake((WIDTH - 120) / 2, 600, 120 , 50 );
>>>>>>> 350166339bddca9352362d63ddaedbdcd3ce8617
        button.layer.cornerRadius = 10;
        button.clipsToBounds = YES;
        button.backgroundColor = [UIColor colorWithRed:193 / 255.0 green:252 / 255.0 blue:254 / 255.0 alpha:1];
//        button.alpha = 0.3;
        [button setTitle:@"立即体验" forState:UIControlStateNormal];
        button.showsTouchWhenHighlighted = YES;
        button.titleLabel.font = [UIFont boldSystemFontOfSize:25];
        button.tintColor = [UIColor colorWithRed:103 / 255.0 green:170 / 255.0 blue:1296 / 255.0 alpha:1];
        [button addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];
        image4.userInteractionEnabled = YES;
        [image4 addSubview:button];
        
        
        //极光推送
        // Required
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
            //可以添加自定义categories
            [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |
                                                           UIUserNotificationTypeSound |
                                                           UIUserNotificationTypeAlert)
                                               categories:nil];
        } else {
            //categories 必须为nil
            [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                           UIRemoteNotificationTypeSound |
                                                           UIRemoteNotificationTypeAlert)
                                               categories:nil];
        }
        
        // Required
        [APService setupWithOption:launchOptions];
        

}

     return YES;
    }



- (void)createTabBar
{
    
    
    CXRecommendViewController *recommendVC = [[CXRecommendViewController alloc] init];
    UINavigationController *navi_recommend = [[UINavigationController alloc] initWithRootViewController:recommendVC];
    navi_recommend.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"推荐" image:[UIImage imageNamed:@"iconfont-tuijian.png"] tag:10000];
    navi_recommend.navigationBar.barTintColor = [UIColor colorWithRed:0.35 green:0.73 blue:0.78 alpha:1];
    
    
    CXDestinationViewController *destinationVC = [[CXDestinationViewController alloc] init];
    UINavigationController *navi_destination = [[UINavigationController alloc] initWithRootViewController:destinationVC];
    navi_destination.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"目的地" image:[UIImage imageNamed:@"iconfont-lvyou@2x"] tag:10001];
    
    navi_destination.navigationBar.barTintColor = [UIColor colorWithRed:0.35 green:0.73 blue:0.78 alpha:1];
    
    
    
    ZZXStrategyViewController *strategyVC = [[ZZXStrategyViewController alloc] init];
    UINavigationController *navi_strategy = [[UINavigationController alloc] initWithRootViewController:strategyVC];
    navi_strategy.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"攻略" image:[UIImage imageNamed:@"iconfont-icon7@2x"]tag:1003];
    navi_strategy.navigationBar.barTintColor = [UIColor colorWithRed:0.35 green:0.73 blue:0.78 alpha:1];
    
    
    CXMineViewController *mineVC = [[CXMineViewController alloc] init];
    UINavigationController *navi_mine = [[UINavigationController alloc] initWithRootViewController:mineVC];
    navi_mine.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"iconfont-self.png"] tag:10003];
    navi_mine.navigationBar.barTintColor = [UIColor colorWithRed:0.35 green:0.73 blue:0.78 alpha:1];
    
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.tabBar.barTintColor  = [UIColor colorWithRed:0.85 green:0.84 blue:0.76 alpha:1];
    tabBar.tabBar.tintColor = [UIColor colorWithRed:0.35 green:0.73 blue:0.78 alpha:1];
    
    
    tabBar.viewControllers = @[navi_recommend,navi_destination, navi_mine];
    tabBar.selectedIndex = 0;
    tabBar.viewControllers = @[navi_recommend,navi_destination,navi_strategy, navi_strategy, navi_mine];
    tabBar.selectedIndex = 0;
    self.window.rootViewController = tabBar;
    
}

-(void)go
{
    [UIView animateWithDuration:3 animations:^{
        self.scrollView.alpha = 0;
    } completion:^(BOOL finished) {
        self.scrollView.hidden = YES;
    }];
}


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    // Required
    [APService registerDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    
    // Required
    [APService handleRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    
    
    // IOS 7 Support Required
    [APService handleRemoteNotification:userInfo];
    completionHandler(UIBackgroundFetchResultNewData);
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
